#include "BS_thread_pool.hpp"
#include <iostream>
#include <future>
#include <chrono>
#include <curl/curl.h>
#include <vector>

static size_t writeCallback(void *contents, size_t size, size_t nmemb, std::string *s)
{
    size_t totalSize = size * nmemb;
    s->append((char *)contents, totalSize);
    return totalSize;
}

int main()
{
    curl_global_init(CURL_GLOBAL_DEFAULT);

    const char *url = "https://www.cboe.com/json/bzx/book/MLGO";

    CURL *curl = curl_easy_init();

    std::string response;

    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, url);
        struct curl_slist *headers = NULL;
        headers = curl_slist_append(headers, "Referer: https://www.cboe.com/us/equities/market_statistics/book_viewer/");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
        CURLcode res = curl_easy_perform(curl);
        if (res != CURLE_OK)
        {
            std::cerr << "CURL request failed: " << curl_easy_strerror(res) << std::endl;
        }
        std::cout << response << std::endl;
        curl_slist_free_all(headers);
        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();
    return 0;
}